package br.com.service;

import javax.ejb.Stateless;

import br.com.domain.Perfil;
import br.com.exception.PersistenceException;
import br.com.exception.ServiceException;

/**********************************************************************************/
/** SOBRECARREGAR / CRIAR METODOS QUANDO NECESS�RIO REGRA DE NEG�CIO ADICIONAL   **/
/**********************************************************************************/


@Stateless
public class PerfilService extends GenericServiceImpl  {
	
	/** BUSCAR PERFIL POR NOME **/
	public Perfil buscarPorNomeFixo(String nome) throws ServiceException {
		Perfil retorno = null;
		
		try {
			
			String query    =  " SELECT p FROM Perfil p                             " +
							   " WHERE  p.nome = ?1                                 " +
                               " AND    p.fixo = true                               " ;
			
			retorno = (Perfil) genericDAO.executarQuerySingle(query, nome);
			
		} catch (PersistenceException e) {			
			throw new ServiceException(e.getMessage(), e);
		}
		
		return retorno;
	}
	
	/** EXCLUIR POR PERFIL **/
	public void excluirPorPerfil(Perfil perfil) throws ServiceException {
		try {
			
			String query    =  " DELETE FROM PerfilMenu p" +
							   " WHERE p.perfil.id = ?1";
			
			 genericDAO.executarQueryExecute(query, perfil.getId());
			
		} catch (PersistenceException e) {			
			throw new ServiceException(e.getMessage(), e);
		}
		
	}


}
